package com.wk.design.template;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

public class BookDao extends JdbcTemplate{
    public BookDao(DataSource dataSource) {
        super(dataSource);
    }
    public List<?> selectAll(){
        String sql = "select * from book";
        return super.excuteQuery(sql, new RowMapper<Book>() {
            @Override
            public Book mapRow(ResultSet rs, int rowNum) throws Exception {
                Book book = new Book();
                book.setId(rs.getLong("id"));
                book.setName(rs.getString("name"));
                book.setAuthor(rs.getString("author"));
                book.setLastCh(rs.getString("last_ch"));
                book.setCreateTime(rs.getDate("create_time"));
                book.setUpdateTime(rs.getDate("update_time"));
                return book;
            }
        }, null);
    }

    public static void main(String[] args) {
        BookDao bookDao = new BookDao(null);
        List<?> result = bookDao.selectAll();
        System.out.println(result);
    }
}
